Cnbi.model.Cost=function(params){
	CnbiSoft.setCurrentRenderer('JavaScript');
	var me = this , _config = {};this.datas={"cwfy":1.3,"cwfyL":2.64,"glfy":6.45,"glfyL":17.82,"gyzbddsy":0.0,"gyzbddsyL":0.0,"lrze":15.15,"lrzeL":39.73,"tzsy":-0.03,"tzsyL":-0.18,"xsfy":12.22,"xsfyL":34.67,"yycb":67.84,"yycbL":176.45,"yysjjfj":1.97,"yysjjfjL":5.55,"yysr":104.49,"yysrL":276.51,"zcjzsf":-0.01,"zcjzsfL":-0.03};
	Utils.applyIf(_config,params);
	me.flag = false;this.defaults=params;
	//this.defaults["params"] = params;
	this.hasCache=false;
	this.bindChangeCondition= function(){
		$("body >div ").eq(0).css("background-color", "#fff");
    	$("body >div ").eq(1).css("background-color", "#fff");
    	    $("#compareYear").parent().remove();
    	    $("#compareMonth").parent().remove();
    	var e = "#year,#month,#company,#unit";
    	$("#year").val(me.defaults["params"]["year"]);
    	$("#month").val(me.defaults["params"]["month"]);
    	$("#company").val(me.defaults["params"]["company"]);
    	 $("#unit").val(me.defaults["params"]["unit"]);
    	//console.dir(e);
        $(e).change(function(){
        	console.dir(me.defaults["params"]);
        var id = $(this).attr("id"),val =$(this).val() ;
        me.defaults["params"][id] =val ;
        me.init();
	   });
	   
	   $(".cnbi-collapse").click(function(){
			var obj = $(".cnbi-panel-content:first");
			obj.toggle();
			if(obj.is(":hidden")){
				$(this).prop("class","cnbi-collapse cnbi-open").prop("title","单击打开");
				
			}else{
				$(this).prop("class","cnbi-collapse cnbi-close").prop("title","单击隐藏");
			}
		});
    }
	var industryB={};
	var   index_key="";
    this.init=function(){
    	if(me.flag==false){
    		this.bindChangeCondition();
    		 var obj = {
				isSys:true,
				url:url,
				com_id:11,
				bean:me
				
			};
			//var com = new ComTree().init(obj);
    		divSliderClick();
    	};
    	$("body > div").eq(1).mask("正在努力为您加载数据，请稍候......");
    	this.ajax();
    	me.flag = true;
    };
    /**
     * 获取模型数据方法
     */
    this.ajax=function(){
    	  index_key=encodeURIComponent(me.defaults["url"]+me.defaults["params"]["company"]+me.defaults["params"]["year"]+me.defaults["params"]["month"]+me.defaults["params"]["unit"]+params["params"]["query"]);
    	  var cacheData = Utils.getLocalStorage(index_key);
         if(cacheData ==null){
	        Utils.doAsyncRequest(me.defaults["url"],me.defaults["params"], "POST", onSuccess, onFailure);
	     }else{
	     	this.hasCache=true;
	     	var obj  = JSON.parse(decodeURIComponent(cacheData));
	     	me.datas = obj[0];
	        industryB = obj[1]["cbfylrv"];
	     	setBodyData(); 
	     	 $("body > div").eq(1).slideDown("slow");
	    }
    };
    /**
     * 从后台响应成功的方法
     */
    function onSuccess(res){
    	try{
    	    var obj  = JSON.parse(res);
      	  me.datas = obj[0];
	     industryB = obj[1]["cbfylrv"];//cbfylrv
	     //alert(me.datas["yycb"]);
	    if(me.datas["yycb"]=="0"){
	       $("body > div").eq(1).unmask();
    	    alert("您所选择的期间与公司没有数据！");
    	   $("body > div").eq(1).slideUp("slow");
    	   return;
	    }
         	Utils.setLocalStorage(index_key,encodeURIComponent(res));
       	setBodyData();
    	    $("body > div").eq(1).slideDown("slow");
    	}catch(e){//$("p")
    		 $("body > div").eq(1).unmask();
    	    alert("您所选择的期间与公司没有数据！");
    	   $("body > div").eq(1).slideUp("slow");
    	}    
    	    
    
        
    }
    /**
     * 从后台响应失败的方法
     */
     function onFailure(res){
      // var msg = data.split(">")[1];
    		//msg = msg.substring(0,msg.length-5);
    	// alert("查询出错了:"+msg);
    	 var obj = [{"cwfy":1.3,"cwfyL":2.64,"glfy":6.45,"glfyL":17.82,"gyzbddsy":0.0,"gyzbddsyL":0.0,"lrze":15.15,"lrzeL":39.73,"tzsy":-0.03,"tzsyL":-0.18,"xsfy":12.22,"xsfyL":34.67,"yycb":67.84,"yycbL":176.45,"yysjjfj":1.97,"yysjjfjL":5.55,"yysr":104.49,"yysrL":276.51,"zcjzsfL":-0.03,"zcjzss":-0.01},{"cbfylrv":{"average":2.1,"excellent":8.1,"good":4.9,"lowers":-2.3}}];

        me.datas = obj[0];
	    industryB = obj[1]["cbfylrv"];
       setBodyData();
    }
  /**
     * 从后台响应成功，失败都执行的方法
     */
    function setBodyData(){
    	console.dir(me.datas);
    	setFomular();
    //	console.dir("------------------");
    	//console.dir(me.datas);
    	//console.dir(industryB);
       	me.createAngularGauge();
    	me.initOnePage();
    	me.initPage();
    	 $("body > div").eq(1).unmask();
    }
    this.initOnePage=function(){//   legendAllowDrag caption="成本费用各项对比图"     
    	var datasb={yycb:me.datas["yycb"],xsfy:me.datas["xsfy"],cwfy:me.datas["cwfy"],glfy:me.datas["glfy"],yysjjfj:me.datas["yysjjfj"]},
    	    datasl={yycb:me.datas["yycbL"],xsfy:me.datas["xsfyL"],cwfy:me.datas["cwfyL"],glfy:me.datas["glfyL"],yysjjfj:me.datas["yysjjfjL"]},
    	 array=[{index0:"项目",index1:"本期",index2:"累计"},[{index0:"营业成本",index1:datasb["yycb"],index2:datasl["yycb"]},{index0:"销售费用",index1:datasb["xsfy"],index2:datasl["xsfy"]},{index0:"财务费用",index1:datasb["cwfy"],index2:datasl["cwfy"]},{index0:"管理费用",index1:datasb["glfy"],index2:datasl["glfy"]},{index0:"税金附加",index1:datasb["yysjjfj"],index2:datasl["yysjjfj"]}]];
    	//console.dir(datasl);
    		//console.dir(datasb);
    	new Cnbi.model.Chart({chartType:2,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表 exportEnabled="1"
	            swfName:"MSColumn3D",//这个就不用说了吧！  //Column2D.swf Column3D MSColumn3D
	            datas:array,//显示的数据  注意：规定的数据解析格式
	            domId:params.domArray[1][0],//渲染的dom节点
	            color:["1C86EE","EEC900"], //颜色
	            percent:true,
	          	attributes:'showBorder="0" formatNumberScale="0" showValues="1"  palette="3" bgColor="#fff"',// numberPrefix="￥" 
	          	width:'95%',height:'95%'});
    	
    	 var  obj1={domId:params.domArray[1][1],datas:datasb}, obj2={domId:params.domArray[1][2],datas:datasl};
    	 new Cnbi.model.Chart(getPieObj(obj1))
    	 new Cnbi.model.Chart(getPieObj(obj2))
         
    };
     this.initPageRender=function(o){
     	//console.dir("---"+me.datas["yycb"]+"-----"+me.datas["cbfyze"]);
     	var bj=o["o"]["index1"],lj=o["o"]["index2"],
     	 array=[{index0:"项目",index1:"本期",index2:"累计"},[{index0:"营业成本",index1:Utils.formatFloat(me.datas["yycb"]/bj,2)*100,index2:Utils.formatFloat(me.datas["yycbL"]/lj,2)*100},{index0:"销售费用",index1:Utils.formatFloat((me.datas["xsfy"]/bj)*100,2),index2:Utils.formatFloat(me.datas["xsfyL"]/lj,2)*100},{index0:"财务费用",index1:Utils.formatFloat((me.datas["cwfy"]/bj)*100,2),index2:Utils.formatFloat(me.datas["cwfyL"]/lj,2)*100},{index0:"管理费用",index1:Utils.formatFloat((me.datas["glfy"]/bj)*100,2),index2:Utils.formatFloat(me.datas["glfyL"]/lj,2)*100},{index0:"税金附加",index1:Utils.formatFloat(me.datas["yysjjfj"]/bj,2)*100,index2:Utils.formatFloat(me.datas["yysjjfjL"]/lj,2)*100}]],
     
     	obj={percentData:[bj,lj],domId:o["tableDomId"],datas:[o["o"],{index0:"营业成本",index1:me.datas["yycb"],index2:me.datas["yycbL"]},{index0:"销售费用",index1:me.datas["xsfy"],index2:me.datas["xsfyL"]},{index0:"财务费用",index1:me.datas["cwfy"],index2:me.datas["cwfyL"]},{index0:"管理费用",index1:me.datas["glfy"],index2:me.datas["glfyL"]},{index0:"税金附加",index1:me.datas["yysjjfj"],index2:me.datas["yysjjfjL"]}]};
    	//alert("bj==="+bj+"--lj==="+lj);
    //	console.dir(array);
    	new Cnbi.model.Chart({chartType:2,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表 exportEnabled="1"
        swfName:"MSColumn3D",//这个就不用说了吧！  //Column2D.swf Column3D MSColumn3D
        datas:array,//显示的数据  注意：规定的数据解析格式
        domId:o["chartDomId"],//渲染的dom节点
        color:["1C86EE","EEC900"], //颜色
        percent:true,
      	attributes: 'showValues="0"  numberPrefix="%"  alternateVGridColor="AFD8F8" baseFontColor="114B78" toolTipBorderColor="114B78" toolTipBgColor="E7EFF6" plotBorderDashed="0" plotBorderDashLen="2" plotBorderDashGap="2"  useRoundEdges="1" showBorder="0" bgColor="FFFFFF,FFFFFF" formatNumberScale="0" baseFontSize="14" baseFont="微软雅黑"',// numberPrefix="￥" 
      	width:'95%',height:'95%'});
      	
       	createDataGrid(obj);
     };
     this.initPage=function(){
       var 	obj2={index0:"成本费用总额",index1:me.datas["cbfyze"],index2:me.datas["cbfyzeL"]},
       		obj3={index0:"营业收入",index1:me.datas["yysr"],index2:me.datas["yysrL"]},
       		o2={o:obj2,tableDomId:params.domArray[2][1],chartDomId:params.domArray[2][0]},
       		o3={o:obj3,tableDomId:params.domArray[3][1],chartDomId:params.domArray[3][0]};
       		me.initPageRender(o2);
       		me.initPageRender(o3);
       		
     };
    this.createAngularGauge=function(){
    	var colorArray = ["#228B22","#EEC900","#CC0000"],
	       arr=["良好值>"+industryB["good"],industryB["average"]+"<平均值<"+industryB["good"],"较低值<"+industryB["average"]],
    	   obj1={domId:params.domArray[0],datas:me.datas["cbfylrv"],range:industryB};
    	    $(".tushi").each(function(i,obj){
	              $(obj).css("background-color",colorArray[i]);
	               $(obj).text(arr[i]);
	       });
	      // if(!me.flag){
	       //	alert(me.flag);
	         new Cnbi.model.Chart(getAngularGaugeObj(obj1));
	      // }else{
	          // get(params["domId"]+"_cnbi_chartId")
	                 	//alert(me.flag);
	      // }
     
    };
    function getPieObj(obj){
       return {	chartType:1,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swfName:"Pie2d",//这个就不用说了吧！  //AngularGauge.swf
	            datas:[{index0:"",index1:""},[{index0:"营业成本",index1:obj.datas["yycb"]},{index0:"销售费用",index1:obj.datas["xsfy"]},{index0:"财务费用",index1:obj.datas["cwfy"]},{index0:"管理费用",index1:obj.datas["glfy"]},{index0:"税金附加",index1:obj.datas["yysjjfj"]}]],//显示的数据  注意：规定的数据解析格式
	            domId:obj["domId"],//渲染的dom节点
	            color:["1C86EE","EEC900","6B8E23","9400D3","FF0000"], //颜色
	            percent:true,
	          	attributes:'manageResize="1"  showLabels="1" formatNumberScale="0" chartTopMargin="-10" chartLeftMargin="-20"  legendAllowDrag="0" minimiseWrappingInLegend="0" showBorder="0"   legendBorderThickness="0" legendBorderColor="ffffff" legendBorderAlpha="0" bgColor="ffffff" bgAlpha="0,0" showValues="0" isSmartLineSlanted="1" pieSliceDepth="100"  showLegend="0"',// numberPrefix="￥" 
	          	width:'100%',height:'100%'};
    }
    function getAngularGaugeObj(params){//chartLeftMargin="-200
    		var range = params["range"],
    	 data = params["datas"],color="393";
    	if(data<range["average"]){
    	    color="CC0000";
    	}else if(data>=range["average"]&&data<range["good"] ){
    	   color="FF6";
    	}else{
    	    color="228B22";
    	}
    	//console.dir(params["range"]);
    	//console.dir(data+"---"+color);
    	
      var  attributes='manageResize="1" bgColor="FFFFFF" bgAlpha="0" showBorder="0" lowerLimit="'+range["lowers"]+'" upperLimit="'+range["excellent"]+'" showTickMarks="1" showTickValues="1" showLimits="0" numberSuffix="%" decmials="0" cylFillColor="'+color+'" baseFontColor="'+color+'" chartLeftMargin="15" chartRightMargin="15" chartTopMargin="15"',
    	annotations='<annotationGroup showBelow="1">'+
                     '<annotation type="rectangle"  x="$chartStartX+1" y="$chartStartY+1" toX="$chartEndX-1" toY="$chartEndY-1" color="FFFFFF" alpha="100" showBorder="1" borderColor="'+color+'" borderThickness="2" radius="10"/>'+
               		'</annotationGroup>';
	     return {chartType:3,//图表类型 ：0为单值数据图表;1为多单数据图表;2为多系数据图表
	            swfName:"Cylinder",//这个就不用说了吧！  //AngularGauge.swf  Cylinder
	            datas:params["datas"],//显示的数据  注意：规定的数据解析格式  numberSuffix="%"
	            domId:params["domId"],//渲染的dom节点
	            attributes:attributes,
	            color:["CC0000","FF6","228B22"], //颜色good 
	            annotations:annotations,
	          	colorRange:[range["lowers"],range["average"],range["good"],range["excellent"]],//chartType==0时才有此属性
	          	width:'70%',height:'90%'};
    };
    function setFomular(){
		//营业利润=营业收入-营业成本-营业税金及附加-销售费用-管理费用-财务费用-资产减值损失+公允价值变动收益+投资收益
    	me.datas["yylr"] = Utils.formatFloat(me.datas["yysr"]-me.datas["yycb"]-me.datas["yysjjfj"]-me.datas["xsfy"]-me.datas["glfy"]-me.datas["cwfy"]-me.datas["zcjzss"]+me.datas["gyzbddsy"]+me.datas["tzsy"],2);// 
		//成本费用总额=营业成本+ 营业税金及附加+销售费用+管理费用+ 财务费用
    	me.datas["cbfyze"] = Utils.formatFloat(me.datas["yycb"]+me.datas["yysjjfj"]+me.datas["xsfy"]+me.datas["glfy"]+me.datas["cwfy"],2);
		me.datas["cbfyzeL"] = Utils.formatFloat(me.datas["yycbL"]+me.datas["yysjjfjL"]+me.datas["xsfyL"]+me.datas["glfyL"]+me.datas["cwfyL"],2);
    	//成本费用利润率=利润总额/成本费用总额*100%
    	me.datas["cbfylrv"] = Utils.formatFloat((me.datas["lrze"]/me.datas["cbfyze"])*100,2);
    }
    function createDataGrid(o){
    	var _domId=o["domId"], _width=$("#"+_domId).parent().width(), _height=$("#"+_domId).parent().height(), _striped=true, singleSelect=true,_data = o["datas"],percentData = o["percentData"];
       				 $("#"+_domId).datagrid({
						width:_width,
						height:_height,
						nowrap: true,
						striped:_striped,
						singleSelect:_striped,	
						fitColumns:true,
						columns:[[
							{field:'index0',title:'项目',width:140,align:"center",formatter:function(value,rowData,rowIndex){
								if(value!=undefined)
									return  "<div style='width:"+(140*0.95)+"px;text-align:left'>"+value+"</div>";
							}
							},
							{field:'index1',title:'本期数',width:137,align:"center",formatter:function(value,rowData,rowIndex){
								if(value!=undefined)
									return  "<div style='width:"+(137*0.95)+"px;text-align:right'>"+Utils.formatNumber(value,2)+"</div>";
								}},
							{field:'index3',title:'占比(%)',width:136,rowspan:2,align:"center",formatter:function(value,rowData,rowIndex){
									return  "<div style='width:"+(136*0.95)+"px;text-align:right'>"+Utils.formatNumber((rowData["index1"]/percentData[0])*100,2)+"</div>";
								}},
							{field:'index2',title:'累计娄',width:135,align:"center",formatter:function(value,rowData,rowIndex){
								if(value!=undefined)
									return  "<div style='width:"+(135*0.95)+"px;text-align:right'>"+Utils.formatNumber(value,2)+"</div>";
								}},
							{field:'index4',title:'占比(%)',width:135,rowspan:2,align:"center",formatter:function(value,rowData,rowIndex){
									return  "<div style='width:"+(135*0.95)+"px;text-align:right'>"+Utils.formatNumber((rowData["index2"]/percentData[1])*100,2)+"</div>";
								}}
						]]

					
				});
			 $("#"+_domId).datagrid("loadData",_data);
    }
    function divSliderClick(){
			  	var player  = {index:0,isNext:false},$li_arr = $(".nav-tabs > li");
			        $li_arr.bind("click",function(){
			 		var $qh = $(".slider-div");
					if(player.isNext){
						return ;
					}												
					player.isNext = true;
		 			var num = $qh.size();//兄弟个数
		 			var index = $(this).index();//当前索引
		 			 var indexs=$(this).index()+1;//当前索引+1
		 			if(index==0){
		 			  $(".wrap-left").height("86.5%");
		 			}else{
		 			    $(".wrap-left").height("79%");
		 			}
		 			
		 			if( $li_arr.eq(index).attr("complete") != "1"){
		 				//doRenderPage(indexs);
		 			}
		 			var ol = $qh.eq(index)[0].offsetLeft;
	 				ol = Math.abs(ol);
	 				if(index < num && index >player.index){
	 					$qh.animate({
	 						left:'-='+ol
	 					},function(){
	 						 player.index = index;
	 					});		
	 				}else if(index < player.index){
		 				$qh.animate({
		 					left:'+='+ol
		 				},function(){
		 					 player.index = index;
		 				});
	 			}
	 				
	 			  $(this).addClass("active").siblings().removeClass("active");
	 			  $li_arr.eq(index).attr("complete",1);
		 			setTimeout(function(){
		 				player.isNext= false;
		 			},600);
				   }); 
					
		 }
//		function doRenderPage(page){
//				var _url_path = url["url"]+ "model/cbfyfx/data"+page+".json",
//					_query =params["params"]["query"],
//					_year =params["params"]["year"],
//				    _month =params["params"]["month"] ,
//				    _company =params["params"]["company"] ,
//				    _func;
//				var onSuccess = function(res){
//					_func = eval("_doReanderPage"+page);
//					_func(res,page);
//				}
//				
//				var onFailure = function(res) {};
//				Utils.doAsyncRequest(_url_path,params["params"], "POST", onSuccess, onFailure);
//				
//			}
	this.init();
}
	/*	<chart manageResize="1" lowerLimit="-40" upperLimit="120" majorTMNumber="11" majorTMColor="A4D1FF" minorTMColor="A4D1FF" majorTMWidth="4" minorTMNumber="3" majorTMThickness="1" baseFontColor="A4D1FF" decmials="0" tickMarkDecmials="0" thmFillColor="FF5904" chartLeftMargin="30" chartTopMargin="40" chartBottomMargin="40" numberSuffix="°" borderThickness="2" thmbulbRadius="20" gaugeOriginX="30">
			<value>32</value>
			<annotations>
				<annotationGroup showBelow="1">
					<annotation type="rectangle" x="$chartStartX" y="$chartStartY" toX="$chartEndX" toY="$chartEndY"  radius="0" showBorder="0" borderThickness="1" fillColor="666666,CCCCCC" fillAlpha="100" fillAsGradient="1" fillAngle="90" fillPattern="linear"/>
					<annotation type="rectangle" x="$chartStartX+5" y="$chartStartY+5" toX="$chartEndX-5" toY="$chartEndY-5"  radius="0" fillColor="CCCCCC,888888" fillAlpha="100,100" fillAsGradient="1" fillAngle="90" fillPattern="linear"/>
					<annotation type="rectangle" x="$chartStartX+10" y="$chartStartY+10" toX="$chartEndX-10" toY="$chartEndY-10" radius="0" fillColor="004F9D"/>
					<annotation type="text" x="78" y="403" label= "F" fontSize="12" fontColor="A4D1FF"/>
				</annotationGroup>
			</annotations>
	<chart manageResize="1" showBorder="0" bgColor="FFFFFF" bgAlpha="0" lowerLimit="0" upperLimit="100" majorTMNumber="11" majorTMHeight="2" minorTMNumber="9" decmials="0" thmFillColor="FF5904" chartLeftMargin="20" chartRightMargin="20" chartTopMargin="40" chartBottomMargin="40" numberSuffix="°" borderThickness="2" thmBulbRadius="30" gaugeOriginX="40">
	<value>32</value>
	<annotations>
		<annotationGroup showBelow="1">
			<annotation type="rectangle" x="$chartStartX" y="$chartStartY" toX="$chartEndX" toY="$chartEndY"  radius="15" showBorder="0" borderThickness="2" fillColor="914800,000000" fillAlpha="100" fillAsGradient="1" fillAngle="45" fillPattern="linear"/>
			<annotation type="rectangle" x="$chartStartX+10" y="$chartStartY+10" toX="$chartEndX-10" toY="$chartEndY-10" radius="10" showBorder="1" borderThickness="2"  fillColor="FFBC79,FFBA75" fillAlpha="50" fillAngle="45"/>
			<annotation type="text" x="77" y="433" label= "C" fontSize="12" fontColor="5D5D5D" bold="1"/>
		</annotationGroup>
	</annotations>
</chart>
<chart manageResize="1" bgColor="F1F1FD" lowerLimit="0" upperLimit="5000" showTickMarks="0" numberSuffix=" Ltrs" tickValueDistance="20" decmials="0" tickMarkDecmials="0" cylFillColor="996633" cylRadius="45" showValue="0">
        <value>3650</value>
        <annotations>
                <annotationGroup x="120" y="60" scaleText="1">
                                <annotation type="rectangle" x="0" y="0" toX="160" toY="60" radius="0" fillcolor="333333" fillAlpha="5"/>
                                <annotation type="line" x="0" y="0" toY="60" color="333333" thickness="2"/>
                                <annotation type="line" x="160" y="0" toY="60" color="333333"  thickness="2"/>
                                <annotation type="line" x="0" y="0" toX="5" color="333333"  thickness="2"/>
                                <annotation type="line" x="0" y="60" toX="5" color="333333"  thickness="2"/>
                                <annotation type="line" x="155" y="0" toX="160" color="333333"  thickness="2"/>
                                <annotation type="line" x="155" y="60" toX="160" color="333333"  thickness="2"/>
                                <annotation type="text" label="Fuel left in tanker" font="Verdana" x="25" y="5" align="left" vAlign="bottom" fontcolor="333333" fontSize="10" isBold="1"/>
                                <annotation type="text" label="(expressed in ltrs)" font="Verdana" x="24" y="20" align="left" vAlign="bottom" fontcolor="333333" fontSize="10"/>
                                <annotation type="text" label="3650" font="Verdana" x="25" y="35" align="left" vAlign="bottom" fontcolor="333333" fontSize="10" isbold="1"/>
                </annotationGroup>
        </annotations>
</chart>
		*/